//
//  CZArenaController.m
//  A01-CZ彩票
//
//  Created by apple on 15-6-13.
//  Copyright (c) 2015年 itcast. All rights reserved.
//
#define kCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#import "CZArenaController.h"
#import "UIView+Ex.h"
@interface CZArenaController ()

@end

@implementation CZArenaController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //1 设置导航条的背景图片
    UINavigationBar *navBar = self.navigationController.navigationBar;
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"NLArenaNavBar64"] forBarMetrics:0];
    
    
    //2 设置导航栏的titleView
    
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"足球",@"篮球"]];
    segmentedControl.width = 120;
    
    //设置每一个segment的背景图片
    [segmentedControl setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentBG"] forState:UIControlStateNormal barMetrics:0];
    [segmentedControl setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentSelectedBG"] forState:UIControlStateSelected barMetrics:0];
    
    //设置第一项默认选中
    segmentedControl.selectedSegmentIndex = 0;
    
    //设置文字颜色
    [segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];
    //20  150  115
    [segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:kCOLOR(20, 150, 115)} forState:UIControlStateNormal];
    
    //注册事件    segmentedControl最常用的事件ValueChanged
    [segmentedControl addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.titleView = segmentedControl;
    
}
//
- (void)valueChanged:(UISegmentedControl *)sender{
    //判断当前是第几个segment
    if (sender.selectedSegmentIndex == 0) {
        NSLog(@"1111");
    }else{
        NSLog(@"2222");
    }
    
    //获取当前索引对应的segment中显示的文本
    NSString *title = [sender titleForSegmentAtIndex:sender.selectedSegmentIndex];
    NSLog(@"%@",title);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
